<template>
	<list-frame :top-frames="topFrames" :loading="loading">
		<template slot="query">
			<el-form size="small" inline v-hasPermi="'359eeef677c64921be9520c91a4e0980'">
				<el-form-item>
					<el-input v-model="queryData.name" clearable placeholder="课题名称" style="width: 180px"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="el-icon-search" @click="queryTableData">查询</el-button>
				</el-form-item>
			</el-form>
		</template>
		<template slot="table">
			<el-table size="medium" ref="table" :data="tableData" height="100%" stripe class="index_table_wrapper">
				<el-table-column label="周次" width="130">
					<template slot-scope="{ row }">
						{{ row.year + '年 第' + row.weekCount + '周' }}
					</template>
				</el-table-column>
				<el-table-column label="实验站名称" prop="name" min-width="140">
					<template slot-scope="{ row }">
						{{ `${row.expName}(${row.room})` }}
					</template>
				</el-table-column>
				<el-table-column label="负责人" prop="headName" width="100"></el-table-column>
				<el-table-column label="课题名称" prop="name" min-width="140"></el-table-column>
				<el-table-column label="用户单位" prop="source" min-width="120"></el-table-column>
				<el-table-column label="用户" prop="userName" width="100"></el-table-column>
				<el-table-column label="机时" prop="machineHour" width="100"></el-table-column>
				<el-table-column label="操作" width="80" v-if="$isHasAuth(tableButton)">
					<template slot-scope="{ row }">
						<el-button
							type="text"
							title="详情"
							icon="sw-icon-view-stroke"
							v-hasPermi="'c252e5cf509f4a6a970ae94d067be86e'"
							@click="handleLookDetail(row.id)"
						></el-button>
						<el-button type="text" title="退回" icon="sw-icon-repeal" v-hasPermi="'17da844c47ed4b3c95c0f930ff7de222'" @click="handleReturnSummary(row.id)"></el-button>
					</template>
				</el-table-column>
			</el-table>
		</template>
		<template slot="page">
			<sw-pagination :total="dataCount" :page.sync="queryData.page" :limit.sync="queryData.limit" @change="queryTableData"></sw-pagination>
		</template>
	</list-frame>
</template>

<script>
import listFrame from '../../common/listFrame';
import { queryUserPiStatPageList, piStatBack } from '@/api/business/tbPiStat';
export default {
	components: { listFrame },
	data() {
		return {
			loading: false,
			queryData: {
				page: 1,
				limit: 15
			},
			dataCount: 0,
			tableData: []
		};
	},
	computed: {
		topFrames() {
			return ['359eeef677c64921be9520c91a4e0980'];
		},
		tableButton() {
			return ['c252e5cf509f4a6a970ae94d067be86e', '17da844c47ed4b3c95c0f930ff7de222'];
		}
	},
	mounted() {
		this.queryTableData();
	},
	methods: {
		//获取表格数据
		async getTableData() {
			let params = { ...this.queryData, type: '2' };
			let result = await queryUserPiStatPageList(params).then((res) => res.data);
			this.loading = false;
			if (result.code === '0') {
				this.dataCount = parseInt(result.count);
				this.tableData = result.data || [];
			}
		},
		queryTableData() {
			this.loading = true;
			this.getTableData();
		},

		async handleReturnSummary(id) {
			let params = { id };
			let result = await piStatBack(params).then((res) => res.data);
			if (result.code === '0') {
				this.$showCustomMessage('success', `退回实验小结成功`);
				this.queryTableData();
			}
		},

		handleLookDetail(id) {
			this.$router.push({ path: '/principal/summary/detail', query: { id } });
		}
	}
};
</script>

<style lang="scss" scoped>
.sw_table_container {
	.el-button {
		font-size: 18px;
		padding: 6px 0;
	}
}
</style>
